/**
 * Created by Ren on 2015/6/3.
 */
function BackGround(ctx, starArray)
{
    this.ctx = ctx;
    this.starArray = starArray;
    this.img = new Image();
    this.img.src = "images/Stars.png"
    this.startImg = new Image();
    this.startImg.src = "images/Start.png"
    this.loseImg = new Image();
    this.loseImg.src = 'images/SpaceShooter_Lose.png'
    this.winImg = new Image();
    this.winImg.src = 'images/SpaceShooter_Win.png';
    this.x = 0;
    this.y = 0;
}
BackGround.prototype.draw = function()
{
    if(keyStatus.KEY_ANY_Status && gameStatus.game_Status != 1)
    {
        if(gameStatus.game_Status != 3)
        {
            gameStatus.game_Status = 1;
        }
    }
    this.ctx.drawImage(this.startImg, this.x, this.y);
    this.ctx.drawImage(this.img, this.x, this.y-450);
    this.ctx.drawImage(this.img, this.x, this.y-900);
    this.ctx.drawImage(this.loseImg, this.x, this.y-1350);
    switch (gameStatus.game_Status)
    {
        case 1:
            this.addStars();
            this.y += 30;
            if(this.y >= 900)
            {
                this.y = 450;
            }
            break;
        case 2:
            this.y += 30;
            if(this.y >= 1350)
            {
                this.y = 1350;
                setTimeout(function(){
                    gameStatus.game_isPlay = true;
                }, 2000);
            }
            break;
    }
}
BackGround.prototype.addStars=function() {
    if(this.starArray.length < 100)
    {
        var star = new Stars(this.ctx, Math.random()*500, Math.random()*200, parseInt(Math.random() * 3), this.starArray);
        this.starArray.push(star);
    }
}
BackGround.prototype.bulletCheck = function(bullet) {
    if (bullet.y > 450) {
        return true;
    }
    return false;
};

BackGround.prototype.enemyCheck = function(enemy) {
    if(enemy.y > 450 || enemy.x < -70 || enemy.x > 600)
    {
        return true;
    }
}
BackGround.prototype.starCheck = function(star) {
    if(star.y > 450 || star.x < 0 || star.x > 600 || gameStatus.game_Status != 1)
    {
        return true;
    }
}